import django_filters

from task.models import TaskLog


class TaskLogFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(method='get_name_filter')

    class Meta:
        model = TaskLog
        fields = ('name', 'success', 'date')

    def get_name_filter(self, queryset, name, value):
        if value:
            queryset = queryset.filter(connection__partner__name__icontains=value)
        return queryset
